# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/8/6 9:18
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : user_service.py
# @Software: PyCharm
# @Version: 2.7.5
from db import user_dao
from utils import my_decorator
from idl_output.ttypes import UserProfile


@my_decorator.handle_exception()
def add_user(user_profile):
	return user_dao.add_user(user_profile)


@my_decorator.handle_exception()
def get_user_by_mobile(mobile):
	orm_data = user_dao.get_user_by_mobile(mobile)
	if not orm_data:
		return None

	thrift_data = UserProfile(id=orm_data.id, user_name=orm_data.user_name, pwd=orm_data.pwd, type_id=orm_data.type_id,
	                          register_time=orm_data.register_time, is_admin=orm_data.is_admin, is_enabled=orm_data.is_enabled,
	                          is_locked=orm_data.is_locked, mobile=orm_data.mobile, phone=orm_data.phone,
	                          email=orm_data.email, tag=orm_data.tag, point=orm_data.point, rank=orm_data.rank,
	                          is_unit=orm_data.is_unit, photo_url=orm_data.photo_url, wenxin=orm_data.wenxin, QQ=orm_data.QQ,
	                          blog=orm_data.blog, alias_name=orm_data.alias_name, IsRealName=orm_data.IsRealName,
	                          IsInfoReady=orm_data.IsInfoReady, default_unit_id=orm_data.default_unit_id, pinyincode=orm_data.pinyincode,
	                          onelevel_count=orm_data.onelevel_count, twolevel_count=orm_data.twolevel_count, threelevel_count=orm_data.threelevel_count)
	return thrift_data


@my_decorator.handle_exception()
def update_user(user_profile):
	return user_dao.update_user(user_profile)

